package com.bifrost.repository;

import com.bifrost.entity.Plan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * @author Lee
 * Create Class on 2018/8/13
 * @com.bifrost.repository
 * @wechat-mall
 */
public interface PlanRepository extends JpaRepository<Plan,Long> ,JpaSpecificationExecutor<Plan>{

    @Query(nativeQuery = true , value = "UPDATE PLAN p SET p.PLAN_STATUS='END' WHERE 0=(SELECT SUM(INVENTORY_AVAILABLE) from plan_item WHERE PLAN_ID= ?1)")
    @Modifying(clearAutomatically = true)
    int resetStatus(Long plan);
}
